package com.wechat.back.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wechat.back.mapper.OperationLogMapper;
import com.wechat.back.pojo.OperationLog;
import com.wechat.back.pojo.tools.PageBean;
import com.wechat.back.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperationLogServiceImpl implements OperationLogService {
    @Autowired
    private OperationLogMapper operationLogMapper;
    @Override
    public PageBean<OperationLog> list(Integer pageNum, Integer pageSize, String optModule, String optType, String nickname, String requestMethod) {
        //1.创建PageBean对象
        PageBean<OperationLog> log = new PageBean<>();

        //2.开启分页查询 PageHelper
        PageHelper.startPage(pageNum,pageSize);

        //3.调用mapper

        List<OperationLog> as = operationLogMapper.list(optModule,optType,nickname,requestMethod);
        //Page中提供了方法,可以获取PageHelper分页查询后 得到的总记录条数和当前页数据
        Page<OperationLog> p = (Page<OperationLog>) as;

        //把数据填充到PageBean对象中
        log.setTotal(p.getTotal());
        log.setItems(p.getResult());
        return log;
    }
}
